"""
Copyright (c) 2022 Huawei Technologies Co.,Ltd.

openGauss is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:

          http://license.coscl.org.cn/MulanPSL2

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
"""
"""
Case Type   : 功能-功能测试
Case Name   : 点击插件菜单打开Tab
Create At   : 2023/4/21
Owner       : n@ningyali
Description :
    1、点击插件的菜单，打开对应的Tab页面
    2、再次点击菜单，还是同一个Tab页面
Expect      :
    1、执行成功
    2、与步骤一页面相同
History     :
"""
import os
import time
import unittest

from selenium.webdriver.common.by import By

from openGaussMigrate.common.base import Base
from openGaussMigrate.common.com_log import ComLog
from openGaussMigrate.common.com_node import Macro
from openGaussMigrate.common.com_unit_action import ComUnitAction


class Install0011(unittest.TestCase):
    def setUp(self):
        self.log = ComLog(self.__class__.__name__)
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        web = Macro('WEB_INFO')
        self.driver = ComUnitAction(web.info['driver_path'], web.info['url'])
        self.driver.open()
        self.driver.login(web.info['user'], web.info['passwd'])

    @Base.retry(max_n=1)
    @Base.save_img_when_err(cls_name='Install0011')
    def test_case1(self):
        """点击插件菜单打开Tab"""
        btn_xpath = '//*[text()="插件管理" and contains(@class, "arco-menu")]'
        tag_xpath = '//*[text()="插件管理" and @class="tag-link"]'
        close_xpath = f'{tag_xpath}/following-sibling::span'
        for i in range(2):
            self.log.info(f'第{i+1}次点击插件菜单打开Tab')
            self.driver.wait_click(btn_xpath)
            self.driver.wait_ele(By.XPATH, tag_xpath)
            self.driver.wait_click(close_xpath)
            time.sleep(1)

    def tearDown(self):
        self.driver.close()
        self.log.info('teardown run finished')
